Skip to content

Fix keyword argument collisions in pyscript function calls - #926

Merged
craigbarratt merged 1 commit into
custom-components:masterfrom
dmamelin:fix/call-func-keyword-collision
Nov 24, 2026
Merged

craigbarratt merged 1 commit into
custom-components:masterfrom
dmamelin:fix/call-func-keyword-collision

Conversation

@dmamelin

Copy link
Copy Markdown
Contributor

Calling echo(func=42) raised TypeError: AstEval.call_func() got multiple values for argument 'func' before echo ran. The evaluator passed echo positionally to its internal func parameter, then forwarded func=42 to the same parameter.

This change makes the evaluator’s internal parameters positional-only throughout the call chain. Scripts can now use func, func_name, ast_ctx, and self as keyword arguments. For example, this call now returns 42:

def echo(func):
    return func

echo(func=42)

Regression tests cover the reported call and **kwargs forwarding to functions and bound methods, including calls from @pyscript_compile code. All 335 tests passed.

@craigbarratt craigbarratt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dmamelin, nice fix. I also checked self=/ast_ctx= through a method with a renamed first parameter, a @classmethod, __init__, super().__init__(**kw) and a property setter, and they all work. Removing any one of the /s fails the new tests.

The task functions in trigger.py have the same problem. Could you fix them in this PR too, with a test for each?

  • task.create(echo, func=1) raises TypeError: ... user_task_create() got multiple values for argument 'func'. Both user_task_create(func, ...) and its inner func_call(func, func_name, new_ast_ctx, ...) need a /.
  • task.add_done_callback(task, callback, ...) collides on task= and callback=.
  • task.executor(func, ...) collides on func=.

@dmamelin

Copy link
Copy Markdown
Contributor Author

Thanks, I'm aware of these. #927 moves the task.* helpers into task_functions.py, so I'll fix them all in a follow-up after it lands.

@craigbarratt

Copy link
Copy Markdown
Member

Thanks @dmamelin, sounds good. Approving; let's do the task.* fixes after #927.

@craigbarratt
craigbarratt merged commit edfcaae into custom-components:master Nov 24, 2026
5 checks passed
dmamelin added a commit to dmamelin/pyscript that referenced this pull request Nov 24, 2026
…ional-only

Follow-up to custom-components#926: keyword arguments such as func, task, callback, domain,
name or event_type are now passed on to the called function, the service
data or the event data, instead of clashing with the parameters of
task.create, task.executor, task.add_done_callback, service.call and
event.fire.
craigbarratt pushed a commit that referenced this pull request Nov 24, 2026
* move task.create, task.add_done_callback and task.executor to task_functions.py

* remove legacy_decorators option

* move time, state and task helpers out of trigger.py

* remove legacy trigger plumbing and trigger.py

* fix watchdog startup/shutdown event annotations

* remove legacy event, mqtt and webhook modules

* warn when unexpected kwargs are ignored because of TRIGGER_KWARGS

* add mqtt to after_dependencies

hassfest accepted the mqtt import only because of the legacy mqtt.py
file, which it treated as an mqtt platform of pyscript.

* make internal parameters of task.*, service.call and event.fire positional-only

Follow-up to #926: keyword arguments such as func, task, callback, domain,
name or event_type are now passed on to the called function, the service
data or the event data, instead of clashing with the parameters of
task.create, task.executor, task.add_done_callback, service.call and
event.fire.
@dmamelin
dmamelin deleted the fix/call-func-keyword-collision branch November 25, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants